package sim.ring.gui;

import java.net.MalformedURLException;
import java.net.URL;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;


public class RingingSimManager {
	
	private static ImageRegistry IMGReg;
	
	 public static URL newURL(String urlName) {
	    try {
	      return new URL(urlName);
	    }
	    catch (MalformedURLException e) {
	      throw new RuntimeException("Malformed URL " + urlName, e);
	    }
	 }
	 
	 private static URL newResourceURL(String relativeURL) {
		 try {
			 return new URL(
					 RingingSimManager.class
					 	.getProtectionDomain()
					 	.getCodeSource()
					 	.getLocation()
					 	.toString() + "../trunk/" + relativeURL);
		 }
		 catch (MalformedURLException e) {
			 throw new RuntimeException("Could not create URL " + relativeURL, e);
		 }
	 }
	 
	 final static String[][] iconMap = new String[][]{
		 { "exitIcon", "icons/application-exit-5.png" },
		 { "configIcon", "icons/configure-2.png" },
		 { "okStatus", "icons/dialog-clean.png" },
		 { "infoStatus", "icons/dialog-declare.png" },
		 { "errorStatus", "icons/dialog-error-7.png" },
		 { "okDialog", "icons/dialog-clean-24.png" },
		 { "infoDialog", "icons/dialog-declare-24.png" },
		 { "errorDialog", "icons/dialog-error-7-24.png" },
		 { "bellIcon", "icons/bell.png" },
		 { "newFolder", "icons/folder-new-6-24.png" },
		 { "newMethod", "icons/format-add-node-24.png" },
		 { "newCategory", "icons/blockdevice.png" },
		 { "aboutInfo", "icons/help-about-3.png" },
		 { "folderIcon", "icons/folder-blue-small.png" },
		 { "categoryIcon", "icons/blockdevice-small.png" },
		 { "methodIcon", "icons/code-function.png" },
		 { "removeNode", "icons/trash-empty-2.png" }
	 };
	
	public static ImageRegistry getIMGReg() {
		if (IMGReg == null) {
			IMGReg = new ImageRegistry();
			for (String[] str : iconMap) {
				IMGReg.put(str[0], ImageDescriptor.createFromURL(newResourceURL(str[1])));
			}
			return IMGReg;
		} else {
			return IMGReg;
		}
	}
	
}
